﻿using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Caching;

namespace Xms.Abp.Caching;

public interface IXmsCache : IDistributedCache, ICacheSupportsMultipleItems
{
    string DataKeyName { get; }
    Task<bool> KeyExistsAsync(string key, CancellationToken cancellationToken = default);
    Task<DistributedCacheEntryOptions> GetExpirationFromCache(string key, CancellationToken cancellationToken = default);


    Task<bool> HashFieldExsitsAsync(string key, string field, CancellationToken cancellationToken = default);
    Task<byte[]> GetHashAsync(string key, string field, CancellationToken cancellationToken = default);
    Task<IEnumerable<KeyValuePair<string, byte[]>>> GetHashAllAsync(string key, CancellationToken cancellationToken = default);
    Task<IEnumerable<KeyValuePair<string, byte[]>>> GetHashManyAsync(string key, IEnumerable<string> fields, CancellationToken cancellationToken = default);
    Task<IEnumerable<string>> GetHashKeysAsync(string key, CancellationToken cancellationToken = default);
    Task SetHashAsync(string key, string field, byte[] value, CancellationToken cancellationToken = default);
    Task SetHashManyAsync(string key, IEnumerable<KeyValuePair<string, byte[]>> items, CancellationToken cancellationToken = default);
    Task RemoveHashAsync(string key, string field, CancellationToken cancellationToken = default);


    Task SetGeoAsync(string key, string member, double longitude, double latitude, CancellationToken cancellationToken = default);
    Task SetGeoAsync(string key, string member, GeoPositionItem position, CancellationToken cancellationToken = default);
    Task SetGeoManyAsync(string key, IEnumerable<KeyValuePair<string, GeoPositionItem>> geos, CancellationToken cancellationToken = default);
    Task<GeoPositionItem> GetGeoAsync(string key, string member, CancellationToken cancellationToken = default);
    Task<IEnumerable<KeyValuePair<string, GeoPositionItem>>> GetGeoManyAsync(string key, string[] members, CancellationToken cancellationToken = default);
    Task<IEnumerable<KeyValuePair<string, GeoPositionItem>>> GetGeoManyAsync(string key, IEnumerable<string> members, CancellationToken cancellationToken = default);
    Task<bool> RemoveGeoAsync(string key, string member, CancellationToken cancellationToken = default);
    Task<double?> GeoDistanceAsync(string key, string member1, string member2, CancellationToken cancellationToken = default);
    Task<GeoRadiusItem[]> GeoRadiusAsync(string key, string member, double radius, CancellationToken cancellationToken = default);
    Task<GeoRadiusItem[]> GeoRadiusAsync(string key, double longitude, double latitude, double radius, CancellationToken cancellationToken = default);


    Task<bool> LockTaskAsync(string key, int initialCount = 1, TimeSpan? expiration = null, CancellationToken cancellationToken = default);
    Task<bool> LockReleaseAsync(string key, int releaseCount = 1, CancellationToken cancellationToken = default);
    Task<bool> LockExtendAsync(string key, TimeSpan? expiration = null, CancellationToken cancellationToken = default);


    Task<long> GetSerialNumberAsync(string key, int quantity = 1, TimeSpan? expiration = null, CancellationToken cancellationToken = default);
}

//public interface IXmsCache<TCacheContext> : IXmsCache
//    where TCacheContext : CacheContext<TCacheContext>
//{
//}
